package stattracker;

public class Achievement implements Comparable<Achievement>, java.io.Serializable
{
	private static final long serialVersionUID = 1L;
	private static final String secretLockedImg = "";
	private AchievementGroup group;
	private String title, description;
	private boolean secret, unlocked;
	private String imgPath, gameURL;
	
	public Achievement(AchievementGroup group, String title, String description, String img, boolean isSecret)
	{
		this.group = group;
		this.title = title; this.description = description;
		secret = isSecret;
		imgPath = img;
		unlocked = false;
		gameURL = "";
	}
	
	public boolean isUnlocked()
	{
		return unlocked;
	}
	
	public void achieved(String url)
	{
		gameURL = url;
		unlocked = true;
	}
	
	public String getGameURL()
	{
		return gameURL;
	}
	
	public String getImagePath()
	{
		if(secret && !unlocked)
			return secretLockedImg;
		else
		{
			if(!unlocked) //Chops adds 'Locked' to the Img path for the locked image
				return imgPath.substring(0, imgPath.length()-4) + "Locked.gif";
			else
				return imgPath;
		}
	}
	
	public String getTitle()
	{
		if(secret && !unlocked)
			return "Secret";
		return title;
	}
	
	public String getDescription()
	{
		if(secret && !unlocked)
			return "Unlock this achievement to learn more.";
		return description;
	}
	
	public AchievementGroup getGroup()
	{
		return group;
	}
	
	//This probably needs some more work
	//Discuss it over how things should be sorted, or if it should be sorted
	public int compareTo(Achievement other)
	{
		//System.out.println("This Rank: " + group.getRank() + "    Other Rank: " + other.getGroup().getRank());
		if(secret && !unlocked)
			return 1; //secret should always go at the bottom
		if(group.getRank() == other.getGroup().getRank())
			return title.compareTo(other.getTitle());
		else
			return ((Integer) group.getRank()).compareTo(other.getGroup().getRank());
	}
}
